class AistockController < ApplicationController

  layout "aistock"
  def home

  end

  # http://0.0.0.0:3000/aistock/trade_review
  def trade_review
    url = "https://d.10jqka.com.cn/v6/time/hs_300102/last.js"
    response = URI.open(url).read
    json_str = response.match(/\{.*\}/)[0]
    stock_data = JSON.parse(json_str)
    @date = stock_data["hs_300102"]["date"]

    doc = Nokogiri::HTML(URI.open("https://stock.10jqka.com.cn/fupan/"))
    @fpzj = doc.css("#fpzj").text # 综述
    @ggbx = doc.css("#block_1889").text # 权重  个股表现  当日表现情况

    @gnzdsj = doc.css("#fp_item_7").css(".layout_width")[2].css(".mod_list li a").map{|x| x['title']} # 国内重大事件
    @gjzdsj = doc.css("#fp_item_7").css(".layout_width")[3].css(".mod_list li a").map{|x| x['title']} # 国际重大事件

  end

  def limit_lists
    limits = LimitList.last_cal_date.blank? ? LimitList.last_pretrade_date : LimitList.last_cal_date
    @limit_lists = limits.select { |limit| limit.limit_times > 1 }.sort_by { |x| x.limit_times }.reverse
  end
end
